<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			
			//修改每个th 的颜色
			  
			// 从数据列表开始   ，自定生成 单行为蓝色，偶数行为红色  js代码生成
			window.onload=function(){
				/*document.getElementsByClassName("aa")[0].style.background="yellow";
				document.getElementsByClassName("bb")[0].style.background="blue";
				document.getElementsByClassName("cc")[0].style.background="blanchedalmond";
				document.getElementsByClassName("dd")[0].style.background="red";*/
				// 改变th的颜色
			/*	var getta=document.getElementsByTagName("table")[0];
				for(var i=0;i<5;i++) {
					var tr=getta.getElementsByTagName("tr")[0].getElementsByTagName("th")[i];
					if(i==0){
						tr.style.background="yellow";
					}else if(i==1){
						tr.style.background="red";
					}else if(i==2){ 
						tr.style.background="blue";
					}else if(i==3){
						tr.style.background="#FF00FF";
					}else if(i==4){
						tr.style.background="green";
					}
				}  */
				
				  
				//
				 var taName=document.getElementsByTagName("table")[0];
				 for (var i=0;i<4;i++) {
				 	var trName=document.createElement("tr");  
				 	taName.appendChild(trName);   
				 	for (var j=0;j<5;j++) {     
				 		var tdName=document.createElement("td"); 
				 		taName.appendChild(tdName);
				 		for (k=0;k<1;k++) {  
				 			var textName=document.createTextNode("大盘鸡");
				 			tdName.appendChild(textName);
				 		}
				 		
				 	}
				 }   
				for (var i=1;i<4;i++) {
					var taName2=document.getElementsByTagName("table")[0];
					var trName2=document.getElementsByTagName("tr")[i];
					
				     
					if(i%2!=0){
						trName2.style.background="blue";
					}else if(i%2==0){
						trName2.style.background="red";
					}
				}
			

				
		
			}
		</script>
	</head>
	<body>
	<table border="1">
				<tr>
					<th class="" >部门名称</th>
					<th class="">部门电话</th>
					<th class="">部门负责人</th>
					<th class="">所属单位</th> 
					<th class="">操作</th>
				</tr>
				<tr id="xy">
					<td>1</td>
					<td>1</td>
					<td>1</td>
					<td>1</td>
					<td>1</td>
				</tr>
				<tr class="tt">
					<td>1</td>
					<td>1</td>
					<td>1</td>
					<td>1</td>
					<td>1</td>
				</tr>
				<tr>
					<td>1</td>
					<td>1</td>
					<td>1</td>
					<td>1</td>
					<td>1</td>
				</tr>

		</table>
	</body>
</html>
